#coding=utf-8
#----------------------
#create_date: '12-10-15'
#模板上下文公用变量处理
#----------------------
__author__ = 'lyhapple'

def current_menu_select(request):
    '''从访问的路径中判断当前是哪个模块，在菜单栏中高亮当前模块的链接'''
    pathInfo = str(request.path_info)
    if pathInfo.startswith("/office"):
        return {"current" : "office"}
    elif pathInfo.startswith("/job"):
        return {"current" : "job"}
    elif pathInfo.startswith("/tg"):
        return {"current" : "tg"}
    elif pathInfo.startswith("/xx"):
        return {"current" : "xx"}
    elif pathInfo.startswith("/busi"):
        return {"current" : "busi"}
    else:
        return {"current" : "home"}

def get_areas(request):
    '''获取当前网站支持的所有城市, 当前登陆城市的区县、商圈'''
    #TODO: 需要写入缓存处理
    from pub.models import City, Districts
    #城市
    cities = City.objects.order_by("id")
    #某市的区县
    districts = None
    if request.session.has_key("city_cn"):
        districts = Districts.objects.filter(city = City.objects.filter(name=request.session["city_cn"])).order_by("id")
    return {"cities" : cities, "districts": districts}
